#include <func.h>
#define N 20000000

typedef struct {
    pthread_mutex_t mutex;
    long num;
}args_t;

void* func(void* p)
{
    args_t *data =(args_t *) p;
    for(int i = 0;i<N;++i)
    {
        pthread_mutex_lock(&(data->mutex));
        data->num+=1;
        pthread_mutex_unlock(&(data->mutex));
    }

}

int main(int argc,char **argv)
{
    args_t data;
    memset(&data,0,sizeof(data));
    pthread_mutex_init(&data.mutex,NULL);

    pthread_t pthid;
    
    struct timeval s,e;
    gettimeofday(&s,NULL);
    pthread_create(&pthid,NULL,func,&data);
    for(int i = 0;i<N;++i)
    {
        pthread_mutex_lock(&data.mutex);
        data.num+=1;
        pthread_mutex_unlock(&data.mutex);
    } 
    pthread_join(pthid,NULL);
    gettimeofday(&e,NULL);
    printf("result: %ld,time :%ld\n",data.num,(e.tv_sec - s.tv_sec)*1000000+e.tv_usec - s.tv_usec);
    return 0;
}

